import { Table } from 'antd';
import React, { useEffect, useState } from 'react';
import { reqSubmitsList } from '../../../../api';


export const Submit = (props) => {
    const columns = [
        {
            title: '提交结果',
            dataIndex: 'verdict',
            
        },
        {
            title: '执行用时',
            dataIndex: 'runTime',

           
        },
        {
            title: '内存消耗',
            dataIndex: 'runMemory',

        },
        {
            title: '语言',
            dataIndex: 'codeLang',

        },
        {
            title: '提交时间',
            dataIndex: 'createTime',

        },
        {
            title: '备注',
            dataIndex: 'remarks',

        },
    ];
    let { value, dataSource } = props
    const [isValid, setIsValid] = useState(false)
    const [submitData, setSubmitData] = useState(dataSource)
    let initialValue = {
        "page": 1,
        "pageSize": 3,
        "problemId": value,
        "username": null,
        "verdict": null, 
        "codeLang": null
    }
    useEffect(async()=>{
        
        let data = await reqSubmitsList(initialValue)
        console.log(data.data.data);
        const result = data.data.data.map((item,index) => {   
            return {
                key: index,
                verdict:item.verdict,
                runTime: item.runTime,
                runMemory: item.runMemory,
                codeLang:item.codeLang,
                createTime:item.createTime,
                remarks: "-----"
            }
        })
        setIsValid(true)
        setSubmitData(result)
    }, [])
    useEffect(()=>{

    },[submitData])
    return (
        <div >
            {
                isValid?<Table
                    columns={columns}
                    dataSource={submitData}
                    bordered={false}
                    pagination={false}
                />:"你没有任何提交记录"
            }
            
        </div>
    )
}